package com.linkwedo.saas.project;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.linkwedo.saas.domain.ProjectReview;
import com.linkwedo.saas.domain.Target;
import com.linkwedo.saas.domain.Task;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbTask entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.db.TbTask
 * @author MyEclipse Persistence Tools
 */

public class ProjectReviewDao extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory.getLogger(ProjectReviewDao.class);
	// property constants
	public static final String PATH = "path";
	public static final String NOTE = "note";
	public static final String PROJECT_ID = "projectId";

	public void save(ProjectReview transientInstance) {
		log.debug("saving ProjectReview instance");
		Session curSession = getSession();
		try {
			curSession.save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public void delete(ProjectReview persistentInstance) {
		log.debug("deleting ProjectReview instance");
		Session curSession = getSession();
		try {
			Transaction tx = curSession.beginTransaction();
			curSession.delete(persistentInstance);
			tx.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public ProjectReview findById(java.lang.Integer id) {
		log.debug("getting ProjectReview instance with id: " + id);
		Session curSession = getSession();
		try {
			ProjectReview instance = (ProjectReview) curSession.get("com.huayanginfo.saas.domain.ProjectReview", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public List findByExample(ProjectReview instance) {
		log.debug("finding ProjectReview instance by example");
		Session curSession = getSession();
		try {
			List results =curSession.createCriteria("com.huayanginfo.saas.domain.ProjectReview").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ProjectReview instance with property: " + propertyName
				+ ", value: " + value);
		Session curSession = getSession();
		try {
			String queryString = "from ProjectReview as model where model."
					+ propertyName + "= ?";
			Query queryObject = curSession.createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public List findByNote(Object note) {
		return findByProperty(NOTE, note);
	}

	public List findByProjectId(Object projectId) {
		return findByProperty(PROJECT_ID, projectId);
	}

	public List findAll() {
		log.debug("finding all ProjectReview instances");
		Session curSession = getSession();
		try {
			String queryString = "from com.huayanginfo.saas.domain.ProjectReview";
			Query queryObject = curSession.createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public ProjectReview merge(ProjectReview detachedInstance) {
		log.debug("merging ProjectReview instance");
		Session curSession = getSession();
		try {
			Transaction tx = curSession.beginTransaction();
			ProjectReview result = (ProjectReview) curSession.merge(detachedInstance);
			tx.commit();
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}finally{
			curSession.close();
		}
		
	}

	public void attachDirty(ProjectReview instance) {
		log.debug("attaching dirty ProjectReview instance");
		Session curSession = getSession();
		try {
			Transaction tx = curSession.beginTransaction();
			curSession.saveOrUpdate(instance);
			tx.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}

	public void attachClean(ProjectReview instance) {
		log.debug("attaching clean ProjectReview instance");
		Session curSession = getSession();
		try {
			Transaction tx = curSession.beginTransaction();
			curSession.lock(instance, LockMode.NONE);
			tx.commit();
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}finally{
			curSession.close();
		}
	}
}